package com.logicvoid.rosiesettingsz;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * @author Derek Reynolds (myn)
 * 
 */
public class Preferences {
	private static final String TAG = "Preferences";
	private static final String PREFS_NAME = "preferences"; // used as main key for SharedPreferences
	public static final Boolean DEBUG = false; // flag to enable/disable debugging
	

	public static Boolean setStringPreferenceValue(String preferenceName,
			String preferenceValue, Context appContext) {
		// setup value to return
		Boolean returnValue = false;

		try {

			// Save user preferences. We need an Editor object to
			// make changes. All objects are from android.context.Context

			SharedPreferences settings = appContext.getSharedPreferences(
					PREFS_NAME, 2); // 2 = MODE_WORLD_WRITEABLE
			SharedPreferences.Editor editor = settings.edit();
			editor.putString(preferenceName, preferenceValue);

			// commit edits
			editor.commit();

			// if successful, lets report that all went well
			returnValue = true;

		} catch (Exception ex) {
			Log.e(TAG, "Exception in setStringPreferenceValue", ex);
		}

		return returnValue;
	}

	public static String getStringPreferenceValue(String preferenceName,
			String defaultValue, Context appContext) {

		// setup value to return
		String returnValue = defaultValue;

		try {

			SharedPreferences settings = appContext.getSharedPreferences(
					PREFS_NAME, 2); // 2 = MODE_WORLD_WRITEABLE
			String PackageName = settings.getString(preferenceName,
					defaultValue);
			return PackageName;

		} catch (Exception ex) {
			Log.e(TAG, "Exception in getStringPreferenceValue", ex);
		}

		return returnValue;

	}

}
